package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.BlackBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lihao on 2018/1/11.
 */

public class BlackListlAdapter extends RecyclerArrayAdapter<BlackBean.DataBean.ListBean> {


    public interface attentionInterFace {
        void remove(int position);
        void look(int position);
        void replay(int position);
    }

    private attentionInterFace attentionInterFace;

    public void attentionInterfaceListener(attentionInterFace listener) {
        attentionInterFace = listener;

    }


    public BlackListlAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyCarePersonlHolder(parent);
    }


    class MyCarePersonlHolder extends BaseViewHolder<BlackBean.DataBean.ListBean> {


        @Bind(R.id.tv_nick_name)
        TextView tvNickName;
        @Bind(R.id.img_head)
        ImageView imgHead;
        @Bind(R.id.tv_remove)
        TextView tvRemove;
        @Bind(R.id.img_not_look)
        ImageView imgNotLook;
        @Bind(R.id.not_look_layout)
        LinearLayout notLookLayout;
        @Bind(R.id.img_reply)
        ImageView imgReply;
        @Bind(R.id.not_reply_layout)
        LinearLayout notReplyLayout;
        @Bind(R.id.tv_add_time)
        TextView tvAddTime;

        public MyCarePersonlHolder(ViewGroup parent) {
            super(parent, R.layout.item_black);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(BlackBean.DataBean.ListBean data) {
            super.setData(data);

            tvNickName.setText(data.nickname);
            Glide.with(BaseActivity.context)
                    .load(data.portrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);

            if (data.you_show.equals("1")) {
                imgNotLook.setImageResource(R.mipmap.ic_selected);
            } else {
                imgNotLook.setImageResource(R.mipmap.ic_notselect);

            }
            if (data.replay_me.equals("1")) {
                imgReply.setImageResource(R.mipmap.ic_selected);
            } else {
                imgReply.setImageResource(R.mipmap.ic_notselect);
            }
            tvAddTime.setText("添加时间:" + data.createtime);

            tvRemove.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    attentionInterFace.remove(getDataPosition());
                }
            });

            notLookLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    attentionInterFace.look(getDataPosition());
                }
            });
            notReplyLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    attentionInterFace.replay(getDataPosition());
                }
            });

        }
    }
}
